package com.ruoyi.teacher.teacherarticle.service.impl;

import java.util.List;

import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.common.utils.uuid.IdUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.teacher.teacherarticle.mapper.TeacherArticleMapper;
import com.ruoyi.teacher.teacherarticle.domain.TeacherArticle;
import com.ruoyi.teacher.teacherarticle.service.ITeacherArticleService;

/**
 * 阅读文章Service业务层处理
 *
 * @author duanxinli
 * @date 2023-11-08
 */
@Service
public class TeacherArticleServiceImpl implements ITeacherArticleService {
    @Autowired
    private TeacherArticleMapper teacherArticleMapper;

    /**
     * 查询阅读文章
     *
     * @param id 阅读文章主键
     * @return 阅读文章
     */
    @Override
    public TeacherArticle selectTeacherArticleById(String id) {
        return teacherArticleMapper.selectTeacherArticleById(id);
    }

    /**
     * 查询阅读文章列表
     *
     * @param teacherArticle 阅读文章
     * @return 阅读文章
     */
    @Override
    public List<TeacherArticle> selectTeacherArticleList(TeacherArticle teacherArticle) {
        return teacherArticleMapper.selectTeacherArticleList(teacherArticle);
    }

    /**
     * 新增阅读文章
     *
     * @param teacherArticle 阅读文章
     * @return 结果
     */
    @Override
    public int insertTeacherArticle(TeacherArticle teacherArticle) {
        teacherArticle.setId(IdUtils.fastUUID());
        if (teacherArticle.getCreateDate()==null){
            teacherArticle.setCreateDate(DateUtils.getNowDate());
        }
        String username = SecurityUtils.getUsername();
        teacherArticle.setCreateBy(username);
        return teacherArticleMapper.insertTeacherArticle(teacherArticle);
    }

    /**
     * 修改阅读文章
     *
     * @param teacherArticle 阅读文章
     * @return 结果
     */
    @Override
    public int updateTeacherArticle(TeacherArticle teacherArticle) {
        return teacherArticleMapper.updateTeacherArticle(teacherArticle);
    }

    /**
     * 批量删除阅读文章
     *
     * @param ids 需要删除的阅读文章主键
     * @return 结果
     */
    @Override
    public int deleteTeacherArticleByIds(String[] ids) {
        return teacherArticleMapper.deleteTeacherArticleByIds(ids);
    }

    /**
     * 删除阅读文章信息
     *
     * @param id 阅读文章主键
     * @return 结果
     */
    @Override
    public int deleteTeacherArticleById(String id) {
        return teacherArticleMapper.deleteTeacherArticleById(id);
    }
}
